#define _USE_MATH_DEFINES

#include <iostream>
#include <fstream>
#include <datatable.h>
#include <bspline.h>
#include <bsplinebuilder.h>
#include <nlohmann/json.hpp>
#include <vector>
#include <cmath>

#include "helper.h"

#include "sampler1.h"

#include "ppformbuilder.h"

using namespace SPLINTER;

int main(int argc, char *argv[])
{
    Sampler1 sampler;
    double start = -1, end = 1;

    int Ns[] = {6, 11, 21, 41, 81};
    std::vector<PPForm> splines;
    for (int i = 0; i < len(Ns); i++)
    {
        auto N = Ns[i];

        DataTable samples_table;
        for (int j = 0; j < N; j++)
        {
            DenseVector x(1);
            x(0) = start + (end - start) * j / (N - 1);
            double y = sampler(x)[0];
            samples_table.addSample(x, y);
        }
        PPForm bspline = PPForm::Builder(samples_table).degree(3).bondary(Boundary::COMPLETE, &sampler).build();

        splines.push_back(bspline);
        plotSpline(bspline, start, end, {{"label", "N=" + std::to_string(N)}});
    }
    show();

    return 0;
}
